git ?I am now going to assume you have set up your Git account on GitLab.
gitstuff that we will use for all operations somewhere on your computer.Note that the Stanford GitLab website is really under https://code.stanford.edu and https://gitlab.stanford.edu redirects to it a URL on that site.
The credentials business can get a bit involved, so I am not going to discuss later.
Goal: Create a repository on Stanford GitLab
ex01These instructions create a project/repository on the remote server. ___
Goal: Clone repository to your local machine.
Clone drop-down. This gives you an option to copy a URL to your clipboard. Choose the https option and copy the corresponding URL.gitstuff folder you created above. This will create a local folder ex01 with a README.md file inside it. On Windows, you do this using the Git Bash shell as shown below.Goal: Associate this directory with Rstudio.
On your local machine, create a new Rstudio project.
You will get something like this. Note the appearance of a Git menu tab on the upper right panel.
README.mdMake changes to the README.md file by clicking on it and adding some junk lines and saving it.
Click on the Rstudio Git tab on the upper right panel. This will show you a window such as the one below.
Notice that the display shows one file modified—the M icon, and two other files .gitignore and ex01.Rproj have question marks associated with them: Git is telling you it does not know about those two files, they seem to have appeared from somewhere!
Click on the .gitignore file at the bottom to see what it contains. Mine shows:
This means that these are files that Git will ignore in all its actions.
On the Rstudio upper right Git tab you will see subtabs.
Choose Commit. This will bring up a new window.
Click on each of the three files to see what has changed. Old stuff is in pink, and new changes are in green. For files added anew, everything is green!
Go ahead and fill out the commit message on the right with something like:
Added project to Rstudio and edited README.
Notice that you got a message dialog as below and nothing changes.
Commit always requires a message; make it meaningful in real work.
You must stage your files before committing.
This just commits the changes you made to your local copy of the repository. Commits are groups of edits you want to group as a unit so that you can make sense of them.
What this means is that even if you clobber your files in the repository, you can always get back to the point at which you committed.
(However, nothing prevents you from your machine being corrupted and completely hosing the ex01 folder. Then nobody can help you unless you have a backup. )
Note that a Push button has appeared on the top right. This Push button allows you to push your changes to the remote server, so that there is a record of your commits on the server.
Goal: To address authentication issues.
In Rstudio, choose Tools -> Global Options -> Git/SVN.
Click on the Create RSA Key button to generate an RSA key. Choose defaults and leave passphrase empty for now.
Remember where Rstudio created the file and open it in Rstudio.
Apply the changes and Rstudio will ask to restart.
On Stanford Gitlab, choose settings
Paste the public key from Rstudio (one line) into the text box. Do not edit, copy as is, into the textbox. Click on the Add key button.
Now you have added an SSH key that makes your identity known to GitLab!
Goal: To now commit without being prompted for authentication
ex02 on GitLab website
ex02gitstuff. Except that you now use the Clone with SSH option (the first one) shown below. On windows, here is how it looks.
On your local machine, create a new Rstudio project. Choose existing directory and navigate to existing gitstuff/ex02 directory.
Make changes to README.md, stage files, commit with a message.
Now push to remote repository. When you press the Push button, you should get something like this.
On the GitLab website, check the files in your ex02 project to ensure that the changes were indeed pushed to the server.
At this point, even if your machine were to crash, you can retrieve your complete set of commits from the remote server and go back to any commit.